package com.school.test.search.function.controller;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.school.test.search.constants.RequestConst;
import com.school.test.search.function.base.controller.BaseTeaAndStuController;
import com.school.test.search.function.interceptor.NotNullInterceptor;
import com.school.test.search.function.service.StudentService;

import java.util.regex.Pattern;

/**
 * @author 马洁
 * @date 2019/12/24 - 22:14
 */
@Before(NotNullInterceptor.class)
public class StudentController extends BaseTeaAndStuController {
    @Inject
    private StudentService service;

    public void index() {
        if (RequestConst.POST.equals(this.getRequest().getMethod())) {
            String name = getTrim("name");
            Pattern regStr = Pattern.compile(".*" + name + ".*");

            renderJson(service.searchName(regStr));
        } else {
            toSearch();
        }
    }

    public void getTestByName() {
        String classesName = getTrim("name");
        // 是否查看补考
        boolean haveMakeUpExam = getBoolean("make_up_exam");

        // 处理所有考试并设置列表信息
        setTestListInfo(service.getTestsByName(classesName, haveMakeUpExam));
        set("classes", classesName);

        render("test.html");
    }
}
